package org.jivesoftware.smack.compression;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

public class Java7ZlibInputOutputStream extends XMPPInputOutputStream
{
  private static final Method method = localMethod;
  private static final boolean supported = method != null;
  private static final int compressionLevel = -1;

  static
  {
    Method localMethod = null;
    try
    {
      localMethod = Deflater.class.getMethod("deflate", new Class[] { [B.class, Integer.TYPE, Integer.TYPE, Integer.TYPE });
    }
    catch (SecurityException localSecurityException)
    {
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
    }
  }

  public Java7ZlibInputOutputStream()
  {
    this.compressionMethod = "zlib";
  }

  public boolean isSupported()
  {
    return supported;
  }

  public InputStream getInputStream(InputStream paramInputStream)
  {
    return new InflaterInputStream(paramInputStream, new Inflater(), 512)
    {
      public int available()
        throws IOException
      {
        if (this.inf.needsInput())
          return 0;
        return super.available();
      }
    };
  }

  public OutputStream getOutputStream(OutputStream paramOutputStream)
  {
    return new DeflaterOutputStream(paramOutputStream, new Deflater(-1))
    {
      public void flush()
        throws IOException
      {
        if (!Java7ZlibInputOutputStream.supported)
        {
          super.flush();
          return;
        }
        int i = 0;
        if (!this.def.needsInput())
        {
          do
          {
            i = this.def.deflate(this.buf, 0, this.buf.length);
            this.out.write(this.buf, 0, i);
          }
          while (i > 0);
          this.out.flush();
        }
        try
        {
          do
          {
            i = ((Integer)Java7ZlibInputOutputStream.method.invoke(this.def, new Object[] { this.buf, Integer.valueOf(0), Integer.valueOf(this.buf.length), Integer.valueOf(2) })).intValue();
            this.out.write(this.buf, 0, i);
          }
          while (i > 0);
        }
        catch (IllegalArgumentException localIllegalArgumentException)
        {
          throw new IOException("Can't flush");
        }
        catch (IllegalAccessException localIllegalAccessException)
        {
          throw new IOException("Can't flush");
        }
        catch (InvocationTargetException localInvocationTargetException)
        {
          throw new IOException("Can't flush");
        }
        super.flush();
      }
    };
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.compression.Java7ZlibInputOutputStream
 * JD-Core Version:    0.6.1
 */